home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 18 / AMIGAplus Sonderheft 18 (1999)(ICP)(DE)[!].iso / Forum / MichaelRoth / 3-3-99 / code / codesub.asm < prev    next >
Assembly Source File  |  1998-08-15  |  6KB  |  220 lines

  1. ;// Autor
  2. ;                            %
  3. ;                          %%*%%
  4. ;                        %%%* *%%%
  5. ;                      %%%%* B *%%%%
  6. ;                    %%%%%*  T  *%%%%%
  7. ;                  %%%%%%*   B   *%%%%%%
  8. ;                %%%%%%%*    1    *%%%%%%%
  9. ;              %%%%%%%%*     3     *%%%%%%%%
  10. ;          *%%%%%%%%%%*      M      *%%%%%%%%%%*
  11. ;        %%%%%%%%%%%%*---------------*%%%%%%%%%%%%
  12. ;       %%              A M I G A                %%
  13. ;      %%      B i l l y   T h e   B y t e        %%
  14. ;       %%        © 1997  Michael Roth           %%
  15. ;        %%%%%%%%%%%%*---------------*%%%%%%%%%%%%
  16. ;          *%%%%%%%%%%*      D      *%%%%%%%%%%*
  17. ;              %%%%%%%%*     A     *%%%%%%%%
  18. ;                %%%%%%%*    C    *%%%%%%%
  19. ;                  %%%%%%*   6   *%%%%%%
  20. ;                    %%%%%*  9  *%%%%%
  21. ;                      %%%%* 8 *%%%%
  22. ;                        %%%* *%%%
  23. ;                          %%*%%
  24. ;                            %
  25. ;\\
  26.  
  27. ;// Include
  28.           Include  assem:macro/Dir
  29.           Include  assem:macro/Exec.m
  30.           Include  assem:macro/Dos.m
  31.           Include  Dos/DosExtens.i
  32.           include  macro/filelength
  33. ;\\
  34.  
  35. ;// Libraries öffnen
  36.           OpenDos  37
  37. ;\\
  38.  
  39. ;//ReadArgs
  40.           move.l   #inputstr,d1                  ; Eingabe String
  41.           move.l   #arry,d2                      ; Arry
  42.           move.l   #0,d3                         ; Keine Externe Structur
  43.           Dos      ReadArgs                      ; Argumente Lesen
  44.           move.l   d0,rdargs                     ; speichern
  45.           bne.s    .1                            ; prüfen ob alles o.k.
  46.           error    cleanup,20                    ; o.k. >.1 Ansonsten Fehlermeldung beenden
  47. .1                                               ;
  48.           lea   arry,a0                          ; Arry nach a0
  49. ;\\
  50.  
  51. ;//File Öffnen und gröe bestimmen
  52.           move.l   (a0),d1
  53.           move.l   #MODE_OLDFILE,d2              ; 1005
  54.           Dos      Open                          ; File Öffnen
  55.           bne.s    .2
  56.           error    cleanup,20
  57. .2
  58.           move.l   d0,fh
  59.           filelength fh,filelänge                ; Filelänge bestimmen
  60. ;\\
  61.  
  62. ;// Speicher Reservieren
  63.          move.l    filelänge,d0
  64.          move.l    #MEMF_CLEAR,d1
  65.          Exec      AllocMem
  66.          move.l    d0,memblock
  67.          bne.s     .memallockok
  68.          error     cleanup,20
  69. .memallockok
  70. ;\\
  71.  
  72. ;// File einlesen
  73.          move.l   fh,d1
  74.          move.l   memblock,d2
  75.          move.l   filelänge,d3
  76.          Dos      Read
  77.          cmp.l    filelänge,d0
  78.          beq.s    .readok
  79.          error    cleanup,20
  80. .readok
  81. ;\\
  82.  
  83. key
  84. ;//File Öffnen und gröe bestimmen
  85.           lea      arry,a0                          ; Arry nach a0
  86.           move.l   8(a0),d1
  87.           move.l   #MODE_OLDFILE,d2              ; 1005
  88.           Dos      Open                          ; File Öffnen
  89.           bne.s    .2
  90.           error    cleanup,20
  91. .2
  92.           move.l   d0,fh2
  93.           filelength fh2,filelänge2                ; Filelänge bestimmen
  94. ;\\
  95.  
  96. ;// Speicher Reservieren
  97.          move.l    filelänge2,d0
  98.          move.l    #MEMF_CLEAR,d1
  99.          Exec      AllocMem
  100.          move.l    d0,memblock2
  101.          bne.s     .memallockok
  102.          error     cleanup,20
  103. .memallockok
  104. ;\\
  105.  
  106. ;// File einlesen
  107.          move.l   fh2,d1
  108.          move.l   memblock2,d2
  109.          move.l   filelänge2,d3
  110.          Dos      Read
  111.          cmp.l    filelänge2,d0
  112.          beq.s    .readok
  113.          error    cleanup,20
  114. .readok
  115. ;\\
  116.  
  117. code
  118. ;// Codieren
  119. ******************************************************************
  120.          move.l   memblock,a0                          ; Startadresse des Klartextes
  121.          move.l   memblock2,a1                         ; "" des Keys
  122.          move.l   filelänge,d0                   ; Länge des Buffers
  123.          move.l   filelänge2,d1                  ; Länge des Keys
  124.          lea      (a0,d0),a2                     ; Endadresse des Buffers berechnen
  125.          lea      (a1,d1),a3                     ; """" des Keys
  126. .loop1
  127.          move.b   (a0),d4
  128.          sub.b    (a1)+,d4
  129.          move.b   d4,(a0)+
  130.          cmp.l    a1,a3                          ; Prüfen ob Key am Ende
  131.          bhi.s    .goon                          ; wenn nein weiter
  132.          move.l   memblock2,a1                         ; ansonsten neu laden
  133. .goon                                            ;
  134.          cmp.l    a0,a2                          ; Prüfen ob Buffer am Ende
  135.          bhi.s    .loop1                         ; Nein -> nächste schleife
  136.  
  137.  
  138. ********************************************************************
  139. ;\\
  140.  
  141. ;// Zielfile Öffnen
  142.          lea       arry,a0                          ; Arry nach a0
  143.          move.l    4(a0),d1
  144.          move.l    #MODE_NEWFILE,d2
  145.          Dos       Open
  146.          move.l    d0,d7
  147.          bne       .ok
  148.          error     cleanup,20
  149. .ok
  150.  
  151.          move.l    d7,d1
  152.          move.l    memblock,d2
  153.          move.l    filelänge,d3
  154.          Dos       Write
  155.  
  156.          move.l    d7,d1
  157.          Dos       Close
  158. ;\\
  159.  
  160. ;// CleanUp
  161. cleanup
  162.           move.l   rdargs,d1
  163.           beq.s    .end                          ; Argumente da ?
  164.           Dos      FreeArgs                      ; Wenn Nein beenden
  165.  
  166.           move.l   fh,d1
  167.           beq.s    .1                            ; File geöffnet
  168.           Dos      Close                         ; Wenn nein weiter
  169. .1
  170.           move.l    memblock,d0
  171.           beq.s     .2
  172.           move.l    d0,a1
  173.           move.l    filelänge,d0
  174.           Exec      FreeMem
  175. .2
  176.           move.l   fh2,d1
  177.           beq.s    .3                            ; File geöffnet
  178.           Dos      Close                         ; Wenn nein weiter
  179. .3
  180.           move.l    memblock2,d0
  181.           beq.s     .4
  182.           move.l    d0,a1
  183.           move.l    filelänge2,d0
  184.           Exec      FreeMem
  185. .4
  186.  
  187.  
  188.  
  189. .end
  190.           closedos
  191.           moveq    #0,d0
  192.           rts
  193. ;\\
  194.  
  195. ;// Data
  196.  DATA
  197.  
  198. ver   dc.b "$VER: V0 - Written by DAC698 - Michael Roth",0
  199. inputstr
  200.          dc.b      "Source/A,Dest/A,Key/A",0 ;KeyFile/S",0
  201. cr
  202.          dc.b      10,0
  203.  
  204.  BSS
  205.  cnop 0,4
  206. arry     ds.l      3
  207. rdargs   ds.l      1
  208. fh       ds.l      1
  209. fh2      ds.l      1
  210. filelänge
  211.          ds.l      1
  212. memblock ds.l      1
  213. filelänge2
  214.          ds.l      1
  215. memblock2
  216.          ds.l      1
  217. insert   dc.b      4,0
  218. ;\\
  219.  
  220.